using System.Linq.Expressions;
using UniversalAdmin.Domain.Entities;

namespace UniversalAdmin.Domain.Repositories;

public interface IRepository<T> where T : EntityBase
{
  // 基本CRUD操作
  Task<T?> GetByIdAsync(int id);
  Task<IEnumerable<T>> GetAllAsync();
  Task<IEnumerable<T>> FindAsync(Expression<Func<T, bool>> predicate);
  Task<IEnumerable<T>> FindAsync(Expression<Func<T, bool>> predicate, CancellationToken cancellationToken);
  Task AddAsync(T entity);
  Task AddRangeAsync(IEnumerable<T> entities);
  Task UpdateAsync(T entity);
  Task UpdateRangeAsync(IEnumerable<T> entities);
  Task RemoveAsync(T entity);
  Task RemoveRangeAsync(IEnumerable<T> entities);

  // 高级查询支持
  Task<bool> AnyAsync(Expression<Func<T, bool>> predicate);
  Task<int?> CountAsync(Expression<Func<T, bool>>? predicate = null);

  // 分页查询
  Task<(IEnumerable<T> Items, int TotalCount)> GetPagedAsync(
      Expression<Func<T, bool>>? predicate = null,
      Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
      int pageIndex = 1,
      int pageSize = 10,
      params string[] includeProperties);
}